export class WS {
	constructor(config){
		this.wsUrl = config.wsUrl;
	}

	connect(method = 'GET') {
		uni.connectSocket({
			url: this.wsUrl,
			complete: (res)=> {
			}
		});
	}

	sendMessage(data = {}){
		uni.sendSocketMessage({
		    data
		});
	}

	onMessage() {
		uni.onSocketMessage(res => {
			console.log(res);
		});
	}

	onOpen() {
		uni.onSocketOpen(res => {
		  console.log('WebSocket连接已打开！');
		});
	}

	onError() {
		uni.onSocketError(res => {
		  console.log('WebSocket连接打开失败，请检查！');
		});
	}
}
